import { Injectable } from '@angular/core';

export class Task {
  constructor(
    public id: number,
    public name: string,
    public color: string,
    public process: number,
    public lable: string
  ){}
}

let TASKS = [
  new Task(1, 'Update software',  'red',  55,'55'),
  new Task(2, 'Clean database',   'yellow',   70,'70'),
  new Task(3, 'Cron job running', 'blue',   30,'30'),
  new Task(4, 'Fix and squish bugs', 'green', 90,'90'),
];

let tasksPromise = Promise.resolve(TASKS);

@Injectable()
export class TaskService {
  getTasks() {
    return tasksPromise;
  }

  getTask(id: number | string) {
    return tasksPromise.then(tasks => tasks.find(task => task.id === +id));
  }
}
